# -*- coding: UTF-8 -*-
from Code.Binder.sc_topic import *
from Code.Binder.sc_proxy import get_active_data_binder, get_passive_data_binder, get_query_data_binder
from Code.Model.Data.sc_data import model_gate
from Code.Model.Controller.sc_logger import logger
from Code.Model.Controller.sc_loader import loader
from Code.Model.Controller.sc_plotter import PlotHandler
from Code.Model.Controller.sc_handler import LoginHandler, SettingsHandler
from Code.Model.Controller.sc_executor import task_handler, exec_handler
from Code.Model.Controller.sc_timer import timer_handler


def init():
    # 数据变更事件绑定数据ID #
    active_binder = get_active_data_binder()
    active_binder.bind(model_gate.app_title_data.get_provider(), MODEL_NOTIFY_APP_TITLE_DATA)
    active_binder.bind(model_gate.app_trees_data.get_provider(), MODEL_NOTIFY_APP_TREES_DATA)
    active_binder.bind(model_gate.app_widgets_data.get_provider(), MODEL_NOTIFY_APP_WIDGETS_DATA)
    active_binder.bind(model_gate.exception_data.get_provider(), MODEL_NOTIFY_EXCEPTION_DATA)
    active_binder.bind(model_gate.try_login_return_data.get_provider(), MODEL_NOTIFY_TRY_LOGIN_RETURN_DATA)
    active_binder.bind(model_gate.new_login_return_data.get_provider(), MODEL_NOTIFY_NEW_LOGIN_RETURN_DATA)
    active_binder.bind(model_gate.login_state_data.get_provider(), MODEL_NOTIFY_LOGIN_STATE_DATA)
    active_binder.bind(model_gate.update_infotext_data.get_provider(), MODEL_NOTIFY_UPDATE_INFOTEXT_DATA)
    active_binder.bind(model_gate.update_progress_data.get_provider(), MODEL_NOTIFY_UPDATE_PROGRESS_DATA)
    active_binder.bind(model_gate.update_printout_data.get_provider(), MODEL_NOTIFY_UPDATE_PRINTOUT_DATA)
    active_binder.bind(model_gate.update_widgets_data.get_provider(), MODEL_NOTIFY_UPDATE_WIDGETS_DATA)
    active_binder.bind(model_gate.single_start_result_data.get_provider(), MODEL_NOTIFY_SINGLE_START_RESULT_DATA)
    active_binder.bind(model_gate.single_upload_result_data.get_provider(), MODEL_NOTIFY_SINGLE_UPLOAD_RESULT_DATA)
    active_binder.bind(model_gate.single_download_result_data.get_provider(), MODEL_NOTIFY_SINGLE_DOWNLOAD_RESULT_DATA)

    # 界面变更事件绑定后端处理函数 #
    passive_binder = get_passive_data_binder()
    passive_binder.bind(VIEW_NOTIFY_EXCEPTION_DATA, logger.error)
    passive_binder.bind(VIEW_NOTIFY_APP_CLOSE_DATA, timer_handler.close)
    passive_binder.bind(VIEW_NOTIFY_APP_CLOSE_DATA, exec_handler.close)
    passive_binder.bind(VIEW_NOTIFY_APP_CLOSE_DATA, PlotHandler.close)
    passive_binder.bind(VIEW_NOTIFY_APP_CLOSE_DATA, loader.close)
    passive_binder.bind(VIEW_NOTIFY_APP_CLOSE_DATA, logger.close)
    passive_binder.bind(VIEW_NOTIFY_TRY_LOGIN_DATA, LoginHandler.try_login)
    passive_binder.bind(VIEW_NOTIFY_NEW_LOGIN_DATA, LoginHandler.new_login)
    passive_binder.bind(VIEW_NOTIFY_DEL_LOGIN_DATA, LoginHandler.del_login)
    passive_binder.bind(VIEW_NOTIFY_ADD_IMAGE_DATA, model_gate.dependence_data.append_photo_image)
    passive_binder.bind(VIEW_NOTIFY_DEL_IMAGE_DATA, model_gate.dependence_data.delete_photo_image)
    passive_binder.bind(VIEW_NOTIFY_START_EXEC_DATA, task_handler.execute_start)
    passive_binder.bind(VIEW_NOTIFY_STOP_EXEC_DATA, task_handler.execute_stop)
    passive_binder.bind(VIEW_NOTIFY_UPDATE_SETTINGS_DATA, SettingsHandler.update_settings)
    passive_binder.bind(VIEW_NOTIFY_MAKE_PLOT_PIC_DATA, PlotHandler.make_picture)
    passive_binder.bind(VIEW_NOTIFY_SINGLE_START_DATA, exec_handler.execute_start)
    passive_binder.bind(VIEW_NOTIFY_SINGLE_UPLOAD_DATA, exec_handler.execute_upload)
    passive_binder.bind(VIEW_NOTIFY_SINGLE_DOWNLOAD_DATA, exec_handler.execute_download)

    # 查询事件绑定后端处理函数 #
    query_binder = get_query_data_binder()
    query_binder.bind(VIEW_QUERY_APP_TITLE_DATA, model_gate.query_app_title_data)
    query_binder.bind(VIEW_QUERY_ENV_DEFINE_DATA, model_gate.query_env_define_data)
    query_binder.bind(VIEW_QUERY_LOGIN_LIMIT_DATA, model_gate.query_login_limit_data)
    query_binder.bind(VIEW_QUERY_SERVER_DIR_DATA, model_gate.query_server_dir_data)
    query_binder.bind(VIEW_QUERY_PREFERENCE_IP_DATA, model_gate.query_preference_ip_data)
    query_binder.bind(VIEW_QUERY_DEFAULT_PWD_DATA, model_gate.query_default_pwd_data)
    query_binder.bind(VIEW_QUERY_PHOTO_IMAGE_DATA, model_gate.query_photo_image_data)
    query_binder.bind(VIEW_QUERY_PLOT_IMAGE_DATA, PlotHandler.query_plot_image_data)
    query_binder.bind(VIEW_QUERY_ABOUT_INFO_DATA, model_gate.query_about_info_data)
    query_binder.bind(VIEW_QUERY_TREE_VIEW_DATA, model_gate.query_tree_view_data)
    query_binder.bind(VIEW_QUERY_WIDGETS_DATA, model_gate.query_widgets_data)
    query_binder.bind(VIEW_QUERY_RUNNING_TASK_DATA, model_gate.query_running_task_data)
    query_binder.bind(VIEW_QUERY_IPS_STATE_DATA, model_gate.query_ips_state_data)
    query_binder.bind(VIEW_QUERY_SETTINGS_DATA, model_gate.query_settings_data)
    query_binder.bind(VIEW_QUERY_LANG_TYPES_DATA, model_gate.query_language_types)
    query_binder.bind(VIEW_QUERY_LANGUAGE_DATA, model_gate.query_language_data)
    query_binder.bind(VIEW_QUERY_PURE_MODE_DATA, model_gate.query_pure_mode_data)

    return loader.init()
